package com.zhenlong01.zhentest.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import sun.misc.BASE64Decoder;
import java.io.IOException;
import java.util.UUID;
import com.zhenlong01.zhentest.util.OSSUtil;

/**
 * @author Administrator
 * @date 2019-08-30 14:44
 */
@RestController
public class OSSController {
    @PostMapping("/ossupload")
    public String ossupload(String base64) throws IOException {
        BASE64Decoder decoder = new BASE64Decoder();
        byte[] b = decoder.decodeBuffer(base64);
        String pName = UUID.randomUUID().toString();
        OSSUtil.ossUpload(pName+".jpg",b);
        return pName;
//
//        OSSUtil.ossUpload(pName,base64);
//        return pName;
    }

    @GetMapping("/ossdownload")
    public String ossdownload(String pName) throws IOException {
        return "data:image/jpg;base64,"+OSSUtil.ossDownload(pName);
    }
}
